package org.NooLab.texx;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.nio.CharBuffer;

import org.NooLab.texx.components.WorkDataObject;
import org.NooLab.utilities.files.DFutils;
import org.NooLab.utilities.logging.PrintLog;




/**
 * 
 * 
 *
 */
public class RawFileData {

	ByteArrayInputStream bytestream;
	CharBuffer chars ;
	
	WorkDataObject workData; 
	
	boolean binaryFormat = false;
	
	
	
	PrintLog out ;
	DFutils fileutil = new DFutils() ;
	
	// ========================================================================
	public RawFileData( WorkDataObject workdata, PrintLog prnout) {

		workData = workdata ;
		out = prnout ;
	}
	// ========================================================================
	
	
	public int readRawDatafromFile(String filename) {
		
		int result = -1 ;
		
		try {
			
			chars = fileutil.readFile2Chars ( filename, 1000 ) ;
			result = 0;
		} catch (Exception e) {
			e.printStackTrace();
			result = -7;
		}
		
		int bc=0;
		if (result ==0){
			result = chars.length() ;
			for (int i=0;i<result;i++){
				char c = chars.get(i);
				int code = (int)c;
				if ((c>127) ||(c<31)){
					bc++;
					binaryFormat = true;
					if (bc>50){
						break;
					}
				}
			}
		}
		return result ;
	}

	
	public void close() {
		if (chars != null){
			chars.clear() ;
			chars = null ;
		}
	}

	public ByteArrayInputStream get() {
		// TODO Auto-generated method stub
		return null;
	}

}
